﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DAL;
using DAL._4_RepositoryImplement;
using System.Diagnostics;
using System.Data.Linq;
using LinqToSql加入IUnitOfWork;

namespace BLL
{
    public class OrderManager : BLLBase
    {
        public OrderManager()
            : base(new TestDataContext())
        {

        }
        public void GeneratorOrder(Order_Info order)
        {
            GeneratorOrder(order, null);
        }
        public void GeneratorOrder(Order_Info order, Product product)
        {

            #region BLLBase中直接调用公用方法
            IUnitOfWork.IsNotSubmit = true;
            new OrderRepository(IUnitOfWork).Insert(order);//DAL层具体的Repository实现类
            if (product != null)
                LoadRepository<Product>().Insert(product);//BLLBase提供的单纯CURD操作
            IUnitOfWork.SaveChanges();
            #endregion
        }

        public List<Order_Info> GetOrder()
        {
            return LoadRepository<Order_Info>().GetModel().ToList();
        }

        public List<Product> GetProduct()
        {
            //var linq = from data1 in LoadRepository<Product>().GetModel()
            //           join data2 in LoadRepository<ProductDetail>().GetModel()
            //           on data1.ProductID equals data2.ProductID into list
            //           select new Product_Ext
            //           {
            //               CreateDate = data1.CreateDate,
            //               ProductID = data1.ProductID,
            //               ProductName = data1.ProductName,
            //               ProductDetail = list as EntitySet<ProductDetail>,
            //           };

            var linq = LoadRepository<Product>().GetModel();
            return linq.ToList<Product>();
        }

    }
}